import cv2
import numpy as np
# 读取图像
def read_image(image_path):
    image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)  # 读取灰度图像
    if image is None:
        raise ValueError("无法读取图像，请检查路径是否正确！")
    return image

def reload_image(image:np.ndarray):
    print("Shape:", image.shape)  # 输出: (512, 512)
    print("Data type:", image.dtype)  # 输出: float32
    cv2.imwrite("watermarked_image.bmp",image)
    reloaded_image = cv2.imread("watermarked_image.bmp",cv2.IMREAD_UNCHANGED)
    print("Shape:", image.shape)  # 输出: (512, 512)
    print("Data type:", image.dtype)  # 输出: float32
    return reloaded_image

# Zigzag扫描顺序（提取序号为2-17的低频系数，跳过第一个DC分量(0,0)）
def zigzag_order():
    # 完整的 Zigzag 扫描顺序（8x8 矩阵）
    fullzigzagorder = [
        (0, 0), (0, 1), (1, 0), (2, 0), (1, 1), (0, 2), (0, 3), (1, 2),
        (2, 1), (3, 0), (4, 0), (3, 1), (2, 2), (1, 3), (0, 4), (0, 5),
        (1, 4), (2, 3), (3, 2), (4, 1), (5, 0), (6, 0), (7, 0), (7, 1),
        (6, 1), (5, 1), (4, 2), (3, 3), (2, 4), (1, 5), (0, 6), (0, 7),
        (1, 6), (2, 5), (3, 4), (4, 3), (5, 2), (6, 1), (7, 2), (7, 3),
        (6, 3), (5, 3), (4, 4), (3, 5), (2, 6), (1, 7), (2, 7), (3, 6),
        (4, 5), (5, 4), (6, 3), (7, 4), (7, 5), (6, 5), (5, 6), (4, 7),
        (5, 7), (6, 6), (7, 6), (7, 7)

    ]

    # 跳过第一个 DC 分量 (0, 0)
    lowfreqorder = fullzigzagorder[1:17]  # 提取低频系数（序号 2-17）

    # 提取最高频的 16 个系数
    highfreqorder = fullzigzagorder[-16:]  # 提取最后 16 个位置

    return lowfreqorder
